//
//  GridsTextViewTests.swift
//  AmountBodyTests
//
//  Created by Qiu Jishuai on 2018/1/30.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

import XCTest
@testable import AmountBody


class GridsTextViewTests: XCTestCase, TextGridsViewDelegate {

     lazy var textView: TextGridView = {
        let view = TextGridView()
        view.delegate = self
        return view
    }()

    override func setUp() {
        super.setUp()

        textView.reloadData()
    }

    func

    func testCellItemShouldEqualDelegate() {
        textView.layoutSubviews()
        for (index, cell) in textView.cells.enumerated() {
            XCTAssertEqual(cell.configs.map{ $0.text }, attributeTexts(at: index).map{ $0.text })
            XCTAssertEqual(cell.configs.map{ $0.scale }, attributeTexts(at: index).map{ $0.scale })
        }
    }

    //列数
    func testColumsShouldEqualDelegate() {
        XCTAssertEqual(numberOfColumns(), textView.numberOfColumns)
        XCTAssertEqual(numberOfColumns(), textView.columnHeights.count)
    }

    //单元格数量
    func testCellsCountShouldEqualDelegate() {
       XCTAssertEqual(textView.cells.count, numberOfCells())
    }

    //Insets
    func testInsetsShouldEqualDelegate() {
        textView.frame = CGRect(x: 0, y: 0, width: 300, height: 400)
        textView.layoutSubviews()
        let insets = UIEdgeInsets(top: textView.containerView.frame.minY, left: textView.containerView.frame.minX, bottom: textView.frame.height - textView.containerView.frame.maxY, right: textView.frame.width - textView.containerView.frame.maxX)
        XCTAssertEqual(insets, viewInsets())
    }

    func testLayoutSubviewsShouldRedraw() {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
        view.addSubview(view)
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    func numberOfColumns() -> Int {
        return 10
    }

    func columnSize(at column: Int) -> CGSize {
        return CGSize(width: 100, height: 800)
    }

    func itemSpacing(for cellIndex: Int) -> CGFloat {

        return 10
    }

    func columnSpacing(at column: Int) -> CGSize {
        return .zero
    }

    func viewInsets() -> UIEdgeInsets {
        return UIEdgeInsets(top: 1, left: 20, bottom: 0, right: -1)
    }

    func numberOfCells() -> Int {
        return 10
    }

    func attributeTexts(at cellIndex: Int) -> [TextGridView.Cell.TextConfig] {
        return [(text: "呵呵呵", scale: 1)]
    }

}
